//
//  SAMarketingVC.m
//  saasRetail
//
//  Created by 黄志刚 on 2021/1/26.
//

#import "SAMarketingVC.h"
#import "SAUserExpireAPI.h"

@interface SAMarketingVC ()<HTTPAPIDelegate>

@property (nonatomic, strong) SAUserExpireAPI *userExpireAPI;
@property (nonatomic, strong) UILabel *nameLab;
@property (nonatomic, strong) UILabel *weChatLab;

@end

@implementation SAMarketingVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
}

#pragma mark - HTTPAPIDelegate
- (void)fetchData:(id)data fromServerSuccessedWithAPI:(HTTPAPI *)api {
    if (self.userExpireAPI == api) {
        NSString *customerName = data[@"data"][@"name"];
        if (customerName.length == 0) {
            customerName = @"";
        }
        self.nameLab.text = [NSString stringWithFormat:@"客服经理：%@",customerName];
        self.weChatLab.text = [NSString stringWithFormat:@"微信：%@",data[@"data"][@"wx"]];
    }
}

- (void)fetchDataFromServerFailedWithError:(NSError *)error API:(HTTPAPI *)api {
    
}


-(void)clickedCopyBtn {
    UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
    pasteboard.string = self.weChatLab.text;
    [Prompt popPromptViewWithMsg:@"已复制到剪切板!" duration:3];
}

-(void)initUI {
    [self setNavigationItemBackBBIAndTitle:@"销售顾问"];
    self.view.backgroundColor = kLineColor;
    
    UIView *whiteView = [[UIView alloc] initWithFrame:SARectMake(0, StatusHeight + 1, kBaseScreenWidth, 165)];
    whiteView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:whiteView];
    
    UIImageView *icon = [[UIImageView alloc] initWithFrame:SARectMake(150, 25, 75, 75)];
    icon.image = [UIImage imageNamed:@"logo"];
    [whiteView addSubview:icon];
    
    UILabel *nameLab = [[UILabel alloc] initWithFrame:SARectMake(0, 125, kBaseScreenWidth, 20)];
    nameLab.font = kFont(15);
    nameLab.textColor = kBlackColor;
    nameLab.textAlignment = NSTextAlignmentCenter;
    [whiteView addSubview:nameLab];
    self.nameLab = nameLab;
    
    UIView *whiteView2 = [[UIView alloc] initWithFrame:SARectMake(0, StatusHeight + 171, kBaseScreenWidth, 50)];
    whiteView2.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:whiteView2];
    
    UILabel *weChatLab = [[UILabel alloc] initWithFrame:SARectMake(30, 0, 260, 50)];
    weChatLab.font = kFont(15);
    weChatLab.textColor = kBlackColor;
    weChatLab.textAlignment = NSTextAlignmentLeft;
    [whiteView2 addSubview:weChatLab];
    self.weChatLab = weChatLab;
    
    UIButton *copyBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    copyBtn.frame = SARectMake(kBaseScreenWidth - 80, 0, 80, 50);
    [copyBtn setTitle:@"复制" forState:UIControlStateNormal];
    [copyBtn setTitleColor:kBuleColor forState:UIControlStateNormal];
    copyBtn.titleLabel.font = kFont(15);
    [copyBtn addTarget:self action:@selector(clickedCopyBtn) forControlEvents:UIControlEventTouchUpInside];
    [whiteView2 addSubview:copyBtn];
    
    UIView *whiteView3 = [[UIView alloc] initWithFrame:SARectMake(0, StatusHeight + 225, kBaseScreenWidth, 75)];
    whiteView3.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:whiteView3];
    
    UILabel *tipLab = [[UILabel alloc] initWithFrame:SARectMake(30, 18, 340, 16)];
    tipLab.text = @"了解会员管理功能及开通使用请联系此顾问。";
    tipLab.font = kFont(15);
    tipLab.textColor = kBlackColor;
    tipLab.textAlignment = NSTextAlignmentLeft;
    [whiteView3 addSubview:tipLab];
    
    UILabel *tipLab2 = [[UILabel alloc] initWithFrame:SARectMake(30, 41, 340, 16)];
    tipLab2.text = @"工作时间: 周一至周五 9:00至18:00";
    tipLab2.font = kFont(15);
    tipLab2.textColor = kBlackColor;
    tipLab2.textAlignment = NSTextAlignmentLeft;
    [whiteView3 addSubview:tipLab2];
    
    [self.userExpireAPI sendRequestToServerWithActivityViewAndMask:POST];
}


-(SAUserExpireAPI *)userExpireAPI {
    if (!_userExpireAPI) {
        _userExpireAPI = [SAUserExpireAPI apiWithDelegate:self];
    }
    return _userExpireAPI;
}


@end
